{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Ways to Buy Pens and Pencils"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #enumeration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #枚举"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: waysToBuyPensPencils"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #买钢笔和铅笔的方案数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数&nbsp;<code>total</code>&nbsp;，表示你拥有的总钱数。同时给你两个整数&nbsp;<code>cost1</code> 和&nbsp;<code>cost2</code>&nbsp;，分别表示一支钢笔和一支铅笔的价格。你可以花费你部分或者全部的钱，去买任意数目的两种笔。</p>\n",
    "\n",
    "<p>请你返回购买钢笔和铅笔的&nbsp;<strong>不同方案数目</strong>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>total = 20, cost1 = 10, cost2 = 5\n",
    "<b>输出：</b>9\n",
    "<b>解释：</b>一支钢笔的价格为 10 ，一支铅笔的价格为 5 。\n",
    "- 如果你买 0 支钢笔，那么你可以买 0 ，1 ，2 ，3 或者 4 支铅笔。\n",
    "- 如果你买 1 支钢笔，那么你可以买 0 ，1 或者 2 支铅笔。\n",
    "- 如果你买 2 支钢笔，那么你没法买任何铅笔。\n",
    "所以买钢笔和铅笔的总方案数为 5 + 3 + 1 = 9 种。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>total = 5, cost1 = 10, cost2 = 10\n",
    "<b>输出：</b>1\n",
    "<b>解释：</b>钢笔和铅笔的价格都为 10 ，都比拥有的钱数多，所以你没法购买任何文具。所以只有 1 种方案：买 0 支钢笔和 0 支铅笔。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= total, cost1, cost2 &lt;= 10<sup>6</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-ways-to-buy-pens-and-pencils](https://leetcode.cn/problems/number-of-ways-to-buy-pens-and-pencils/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-ways-to-buy-pens-and-pencils](https://leetcode.cn/problems/number-of-ways-to-buy-pens-and-pencils/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['20\\n10\\n5', '5\\n10\\n10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        pen_max = total // cost1 + 2\n",
    "        res = 0\n",
    "        for i in range(pen_max):\n",
    "            temp = cost1 * i\n",
    "            if temp > total:\n",
    "                break\n",
    "            res += (total - temp) // cost2 + 1\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        count=0\n",
    "        pen=total//cost1\n",
    "        for i in range(0,pen+1):\n",
    "            count+=(total-i*cost1)//cost2+1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        cnt=0\n",
    "        for i in range(0,total//cost1+1):\n",
    "            left=total-i*cost1\n",
    "            cnt+=left//cost2+1\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # def buyWays(total):\n",
    "        #     if total < cost1 and total < cost2:\n",
    "        #         return 1\n",
    "        #     return buyWays(total-cost1)+buyWays(total-cost2)+1\n",
    "        # return buyWays(total)\n",
    "        if total < cost1:\n",
    "            return total//cost2 + 1\n",
    "        res = 0\n",
    "        for i in range(total//cost1 + 1):\n",
    "            res += (total-cost1*i)//cost2 + 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        n = total // cost1\n",
    "        ans = 0 \n",
    "        for i in range(n+1):\n",
    "            num = total - cost1 * i\n",
    "            ans += (num // cost2 ) + 1\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res,n = 0,total // cost1 + 1\n",
    "        for i in range(n):\n",
    "            res += ((total-cost1*i)//cost2 + 1 )\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "\n",
    "        res, cnt = 0, 0\n",
    "        while cost1 * cnt <= total:\n",
    "            res += (total - cost1 * cnt) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        result = 0\n",
    "        for num1 in range(total//cost1 + 1):\n",
    "            result += (total - cost1*num1)//cost2 +1\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        n = 0\n",
    "        for i in range(int(total/cost1)+1):\n",
    "            n+=int((total-cost1*i)/cost2)+1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        k = int(total / cost1)\n",
    "        sum = 0\n",
    "        for i in range(k + 1):\n",
    "            pencil_m = total - i * cost1\n",
    "            count = int(pencil_m/cost2)\n",
    "            sum += (count + 1)\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # max_a = total // cost1\n",
    "        # max_b = total // cost2\n",
    "        # if max_a == 0 and max_b == 0:\n",
    "        #     return 1\n",
    "        \n",
    "        # max_loop = max(max_a, max_b)\n",
    "        # cost_min = min(cost1, cost2)\n",
    "        # cost_max = max(cost1, cost2)\n",
    "        # ret_counts = 1\n",
    "        # for i in range(max_loop):\n",
    "        #     ret_counts += ((total - i * cost_min) // cost_max + 1)\n",
    "        # return ret_counts\n",
    "\n",
    "        if cost1 > cost2:\n",
    "            self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "\n",
    "        res, cnt = 0, 0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(0,total+1,cost1):\n",
    "            pencil = total-i\n",
    "            ans += (pencil//cost2+1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        count = 0 \n",
    "        for i in range(total // cost1 + 1):\n",
    "            temp = (total - i * cost1) // cost2 + 1\n",
    "            count += temp\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        num = 0\n",
    "        while num * cost1 <= total:\n",
    "            remains = total - num * cost1\n",
    "            ans += remains//cost2 + 1\n",
    "            num += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            cost1,cost2 = cost2, cost1\n",
    "        pen_max_number = total // cost1\n",
    "        pen_select = pen_max_number + 1\n",
    "        select_num = 0 \n",
    "        for i in range(pen_select):\n",
    "            surplus_money = total - i*cost1\n",
    "            pencil_max_number = surplus_money//cost2\n",
    "            select_num = select_num+pencil_max_number+1\n",
    "        return select_num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        a,b,c=0,0,0\n",
    "        for a in range(total//cost1+1):\n",
    "            b=(total-cost1*a)//cost2\n",
    "            b=b+1\n",
    "            c=b+c\n",
    "        return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "#         out = 0\n",
    "#         num1 = 0\n",
    "#         while total-num1*cost1 >= 0:\n",
    "#             out += (total-num1*cost1)//cost2+1\n",
    "#             num1+=1\n",
    "#         return out\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for x in range(total // cost1 + 1):\n",
    "            ans += (total - (x * cost1)) // cost2 + 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        a=0\n",
    "        for i in range(total//cost1+1):\n",
    "            if i*cost1>total:\n",
    "                break\n",
    "            a = a+(total-cost1*i)//cost2+1\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for x in range(total // cost1 + 1):\n",
    "            y = (total-(x * cost1)) // cost2 + 1\n",
    "            ans += y\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(total // cost1 + 1):\n",
    "            res += (total - i * cost1) // cost2 + 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        pen_max = total // cost1\n",
    "        res = 0\n",
    "        for i in range(pen_max+1):\n",
    "            res += (total-i*cost1)//cost2+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total,cost2,cost1)\n",
    "        res,cnt = 0,0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2+1\n",
    "            cnt +=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        return sum((total-cost1*i)//cost2+1 for i in range(total//cost1+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        n = total // cost1 \n",
    "        ans = 0\n",
    "        for i in range(n+1):\n",
    "            res = total - cost1 * i \n",
    "            ans = res // cost2 + 1 + ans\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        if cost1 < cost2:\n",
    "            cost1, cost2 = cost2, cost1\n",
    "        while total >= 0:\n",
    "            res += total // cost2 + 1\n",
    "            total -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "#         if cost1 < cost2:\n",
    "#             cost1,cost2 = cost2, cost1\n",
    "#         pen_max_number = total // cost1\n",
    "#         pen_select = pen_max_number + 1\n",
    "#         select_num = 0 \n",
    "#         for i in range(pen_select):\n",
    "#             surplus_money = total - i*cost1\n",
    "#             pencil_max_number = surplus_money//cost2\n",
    "#             select_num = select_num+pencil_max_number+1\n",
    "#         return select_num\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        res, cnt = 0, 0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "      k = 0\n",
    "      for i in range(total//cost1+1):\n",
    "        k += (total - cost1 * i)//cost2+1\n",
    "      return k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        tmp=cost1\n",
    "        if cost1>cost2: cost1,cost2=cost2,tmp\n",
    "        if total<cost2: return total//cost1+1\n",
    "        res=1\n",
    "        m = total//cost1\n",
    "        for i in range(m+1):\n",
    "            res+=(total-cost1*i)//cost2\n",
    "        return res+m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "\n",
    "        res = count = 0\n",
    "        while count * cost1 <= total:\n",
    "            res += (total - count * cost1) // cost2 + 1\n",
    "            count += 1\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # if total < cost1 and total < cost2:\n",
    "        #     return 0\n",
    "        cost_1 = cost1 if cost1 > cost2 else cost2\n",
    "        cost_2 = cost1 + cost2 - cost_1\n",
    "        num1 = total // cost_1\n",
    "        way = 0\n",
    "        for i in range(num1,-1,-1):\n",
    "            rest = total - i * cost_1\n",
    "            num2 = rest // cost_2\n",
    "            way += (num2 + 1)\n",
    "        return way"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total,cost2,cost1)\n",
    "        res,cnt = 0,0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2+1\n",
    "            cnt +=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost2 < cost1:\n",
    "            return self.waysToBuyPensPencils(total,cost2, cost1)\n",
    "        # 设买钢笔x支\n",
    "        res,x = 0, 0\n",
    "        while x* cost1 <= total:\n",
    "            res += (total -x* cost1) // cost2 + 1\n",
    "            x+=1\n",
    "        return res\n",
    "\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "                \n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        while total >= 0:\n",
    "            res += total//cost2+1\n",
    "            total -= cost1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # print(total//cost2+1)\n",
    "        count=0\n",
    "        for i in range(total//cost2+1):\n",
    "            j=total-i*(cost2)\n",
    "            j_1=j//cost1+1\n",
    "            # print(j)\n",
    "            # print(j_1)\n",
    "            count+=j_1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        max1 = total // cost1\n",
    "\n",
    "        for i in range(max1 + 1):\n",
    "            remain = total - i * cost1\n",
    "            res += remain // cost2 + 1\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        qty1 = total // cost1 + 1\n",
    "        for i in range(qty1):\n",
    "            cnt = (total - i * cost1) // cost2 + 1\n",
    "            res += cnt\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        cnt = total//cost1\n",
    "        ans = 0\n",
    "        for i in range(cnt+1):\n",
    "            mx = (total-i*cost1)//cost2\n",
    "            ans += mx+1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        if cost1 < cost2:\n",
    "            cost1, cost2 = cost2, cost1\n",
    "        for i in range(total//cost1+1):\n",
    "            res += (total-i*cost1)//cost2+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(total // cost1 + 1):\n",
    "            ans = ans + (total - i * cost1) // cost2 + 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "#\n",
    "# @lc app=leetcode.cn id=2240 lang=python\n",
    "#\n",
    "# [2240] 买钢笔和铅笔的方案数\n",
    "#\n",
    "\n",
    "# @lc code=start\n",
    "class Solution(object):\n",
    "    def waysToBuyPensPencils(self, total, cost1, cost2):\n",
    "        \"\"\"\n",
    "        :type total: int\n",
    "        :type cost1: int\n",
    "        :type cost2: int\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        higher = max(cost1, cost2)\n",
    "        lower = min(cost1, cost2)\n",
    "        max_st = total // higher\n",
    "        ans = 0\n",
    "        for i in range(max_st, -1, -1):\n",
    "            ans += (total - i * higher) // lower + 1\n",
    "        \n",
    "        return ans\n",
    "\n",
    "\n",
    "\n",
    "# @lc code=end\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(total//cost1+1):\n",
    "            res += ((total - cost1*i)//cost2)+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(total//cost1+1):\n",
    "            res += (total-i*cost1)//cost2+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        return sum(i // cost2 + 1 for i in range(total, -1, -cost1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for x in range(total//cost1 +1):\n",
    "            ans += (total - x * cost1) // cost2 + 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # 枚举可以买的钢笔数\n",
    "        cnt = 0\n",
    "        res = 0 \n",
    "        while cnt*cost1 <= total:\n",
    "            res += (total - cnt*cost1) // cost2 + 1\n",
    "            cnt +=1\n",
    "        return res\n",
    "\n",
    "\n",
    "                \n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        n=total//cost1\n",
    "        x=0\n",
    "        for i in range(n+1):\n",
    "            x=x+(total-(i)*cost1)//cost2+1\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        \n",
    "        res = 0\n",
    "        left = total\n",
    "        while left >= 0:\n",
    "            res += left // cost2 + 1\n",
    "            left -= cost1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        res=0\n",
    "        if cost1>cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        return sum((total-i)//cost2+1 for i in range(0,total+1,cost1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        a=0\n",
    "        for i in range(total//cost1+1):\n",
    "            a = a+(total-cost1*i)//cost2+1\n",
    "        return a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # dp[t] = number of ways with total money t\n",
    "        # dp[t-cost1]\n",
    "\n",
    "        # greedy\n",
    "        # cost1 > cost2\n",
    "        # ans\n",
    "        # x, y: cost1, cost2\n",
    "        # x=0, ymax=(total-x*cost1) // cost2\n",
    "        # ans += y\n",
    "        # x=1, ymax=\n",
    "        # xmax = total // cost1\n",
    "        ans = 0\n",
    "        xmax = total // cost1\n",
    "        for x in range(xmax+1):\n",
    "            ymax = (total-x*cost1) // cost2\n",
    "            ans += (ymax+1)\n",
    "\n",
    "        return max(1, ans)\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        max_pens, max_pencils = total // cost1, total // cost2\n",
    "        ans = 0\n",
    "        for i in range(max_pens + 1):\n",
    "            remain = total - i * cost1\n",
    "            ans += (remain // cost2 + 1)\n",
    "        \n",
    "        for i in range(max_pencils + 1):\n",
    "            remain = total - i * cost2\n",
    "            ans += (remain // cost1 + 1)\n",
    "        return int(ans / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 > total and cost2 > total:\n",
    "            return 1\n",
    "        res_num=0\n",
    "        for pen in range(total//cost1 +1):\n",
    "            res_num+=(total-pen*cost1)//cost2+1\n",
    "        return res_num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        maxbuy1 = total//cost1\n",
    "\n",
    "        for i in range(maxbuy1+1):\n",
    "            temp = total\n",
    "            temp -= cost1 * i\n",
    "            maxbuy2 = temp // cost2\n",
    "            ans += maxbuy2+1\n",
    "        \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        while total >= 0:\n",
    "            ans += (total // cost2 + 1)\n",
    "            total -= cost1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        totalzhi1 = total // cost1\n",
    "        result = 0\n",
    "        for i in range(totalzhi1+1):\n",
    "            result += (total - i*cost1) // cost2 + 1\n",
    "        \n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        ans = 0\n",
    "        for i in range(total//cost1 +1):\n",
    "            ans += (total-cost1*i)//cost2 +1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        #枚举法\n",
    "        res = 0\n",
    "        for i in range(total//cost1+1):\n",
    "            x = (total-i*cost1)//cost2 + 1\n",
    "            res += x\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        cost1, cost2 = min(cost1, cost2), max(cost1, cost2)\n",
    "        n2 = 0\n",
    "        ans = 0\n",
    "        while n2*cost2<=total:\n",
    "            ans += (total-n2*cost2)//cost1+1\n",
    "            n2 += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        cost_lcm = lcm(cost1, cost2)\n",
    "        n, m = divmod(total, cost1)\n",
    "        tot1, tot2 = total - m, m\n",
    "        turn, rest = tot1 // cost_lcm, (tot1 % cost_lcm) // cost1\n",
    "        lastA = cost_lcm // cost2\n",
    "        a0, m0 = divmod(tot2, cost2)\n",
    "        sumA = lenA = restS = 0\n",
    "        while True:\n",
    "            if tot1 == 0:\n",
    "                return (1 + a0) * (1 + lenA) + sumA\n",
    "            if lenA == rest:\n",
    "                restS = sumA\n",
    "            tot1 -= cost1\n",
    "            tot2 += cost1\n",
    "            ai, mi = divmod(tot2, cost2)\n",
    "            sumA += ai - a0\n",
    "            lenA += 1\n",
    "            if mi == m0:\n",
    "                break\n",
    "        return (1 + a0) * (1 + n) + sumA * turn + lastA * lenA * (turn - 1) * turn // 2 + restS + lastA * turn * rest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        res, cnt = 0, 0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        m1,m2 = total//cost1,total//cost2\n",
    "        ans = 0\n",
    "        for i in range(m1+1):\n",
    "            ans += ((total-i*cost1)//cost2)+1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        # 设买钢笔x支\n",
    "        res,x = 0, 0\n",
    "        while x* cost1 <= total:\n",
    "            res += (total -x* cost1) // cost2 + 1\n",
    "            x+=1\n",
    "        return res\n",
    "\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "                \n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        cost1_num = total // cost1 + 1\n",
    "        cost2_num = total // cost2 + 1\n",
    "        res = 0\n",
    "        for i in range(cost1_num + 1):\n",
    "            remain_money = total - cost1 * i\n",
    "            if remain_money < 0:\n",
    "                break\n",
    "            res += remain_money // cost2 + 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if total < cost2 and total < cost1:\n",
    "            return 1\n",
    "        \n",
    "        ans = 0\n",
    "        for i in range(total//cost1 + 1):\n",
    "            t = (total - i * cost1) // cost2 + 1\n",
    "            ans = ans + t\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 > cost2:\n",
    "            cost1, cost2 = cost2, cost1  # now, cost1 < cost2\n",
    "        elif cost1 == cost2:\n",
    "            if total // cost1 == 0:\n",
    "                return 1\n",
    "            else:\n",
    "                t = total // cost1\n",
    "                return (t+1) * (t+2) >> 1\n",
    "        res = 0\n",
    "        for c in range(total // cost2 + 1):\n",
    "            # buy c pen2\n",
    "            t = (total - c*cost2) // cost1\n",
    "            # print(c, t)\n",
    "            res += t+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        res, cnt = 0, 0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def waysToBuyPensPencils(self, total: int, cost1: int, cost2: int) -> int:\n",
    "        if cost1 < cost2:\n",
    "            return self.waysToBuyPensPencils(total, cost2, cost1)\n",
    "        res, cnt = 0, 0\n",
    "        while cnt * cost1 <= total:\n",
    "            res += (total - cnt * cost1) // cost2 + 1\n",
    "            cnt += 1\n",
    "        return res\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
